package com.design.YiTong.shop.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.design.YiTong.common.result.Result;
import com.design.YiTong.model.medicinal.MedicinalOrder;
import com.design.YiTong.model.medicinal.MedicinalShare;
import com.design.YiTong.model.medicinal.MedicinalShop;
import com.design.YiTong.shop.service.OrderService;
import com.design.YiTong.shop.service.ShareService;
import com.design.YiTong.shop.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "订单接口")
@RestController
@RequestMapping("/admin/shop")
public class ShopController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private ShopService shopService;
    @Autowired
    private ShareService shareService;
    @PostMapping("/order")
    public Result saveOrder(@RequestBody MedicinalOrder medicinalOrder){
        orderService.saveOrder(medicinalOrder);
        return Result.ok();
    }
    @ApiOperation(value = "查询药品")
    @GetMapping("getorder/{page}")
    public Result showorder(@PathVariable Long page){
        Page<MedicinalOrder> pageParam = new Page<>(page, 10);
        IPage<MedicinalOrder> pageModel=orderService.showorder(pageParam);
        return Result.ok(pageModel);
    }
    @ApiOperation(value = "查询药品")
    @GetMapping("search/{page}")
    public Result searchMedicinal(@PathVariable Long page){
        Page<MedicinalShop> pageParam = new Page<>(page, 10);
        IPage<MedicinalShop> pageModel=shopService.showMedicinal(pageParam);
        return Result.ok(pageModel);
    }
    @ApiOperation(value = "根据id查询药品")
    @GetMapping("getMedById/{id}")
    public Result getById(@PathVariable long id){
        return Result.ok(shopService.searchById(id));

    }
    @ApiOperation(value = "查询共享")
    @GetMapping("search/share/{page}")
    public Result searchShare(@PathVariable Long page){
        Page<MedicinalShare>pageParam=new Page<>(page,10);
        IPage<MedicinalShare>pageModel=shareService.showShare(pageParam);
        return Result.ok(pageModel);
    }
    @ApiOperation(value = "插入共享")
    @PostMapping("save/share")
    public Result saveShare(@RequestBody MedicinalShare medicinalShare){
        shareService.saveShare(medicinalShare);
        return Result.ok();
    }
    @ApiOperation(value = "删除共享")
    @DeleteMapping("remove/{id}")
    public Result removeShare(@PathVariable long id){
        shareService.removeShare(id);
        return Result.ok();
    }
    @ApiOperation(value = "删除药品")
    @DeleteMapping("removeShop/{id}")
    public Result removeshop(@PathVariable long id){
        shopService.removeById(id);
        return Result.ok();
    }
    @ApiOperation(value = "模糊查询")
    @GetMapping("searchByName/{page}/{name}")
    public Result searchByName(@PathVariable Long page,@PathVariable String name){
        Page<MedicinalShop>pageParam=new Page<>(page,10);
        IPage<MedicinalShop>pageModel=shopService.searchByName(pageParam,name);
        return Result.ok(pageModel);
    }
    @ApiOperation(value = "保存药品")
    @PostMapping("saveMed")
    public Result saveMed(@RequestBody MedicinalShop medicinalShop){
        System.out.println(medicinalShop);
        shopService.saveOrupdataMed(medicinalShop);
        return Result.ok();
    }
}
